<template>
  <div class="addadmin">
    <!-- 头部 -->
    <div class="my_header">
      <i class="mui-icon mui-icon-arrowleft" aria-hidden="true" @click="$router.back(-1)"></i>
      <div class="top1">添加管理员</div>
    </div>

    <div class="txlist">
      <!--<div class="row">
                <div class="left"><span>*</span>登录名</div>
                <div class="right"><input v-model="adminList.nick_name" type="text" placeholder="请输入登录名"></div>
            </div>-->
      <div class="row">
        <div class="left"><span>*</span>手机号码</div>
        <div class="right"><input v-model="adminList.mobile" type="text" placeholder="请输入手机号码（登录手机号码）"></div>
      </div>
      <div class="row">
        <div class="left"><span>*</span>登录密码</div>
        <div class="right"><input v-model="adminList.password" type="password" placeholder="请输入登录密码"></div>
      </div>
      <!--<div class="row">
                <div class="left"><span>*</span>真实姓名</div>
                <div class="right"><input v-model="adminList.name" type="text"  placeholder="请输入真实姓名"></div>
            </div>-->

      <van-button size="large" @click="submit()" class="submit1">提 交</van-button>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        token: "",
        adminList: {
          nick_name: "",
          password: "",
          name: "",
          mobile: ""
        }
      };
    },
    created() {
      var token = localStorage.getItem("token");
      var that = this;
      that.token = token;
      that.adminList.password = "";

      // console.log(token)
    },
    methods: {
      // 提交表单数据
      submit() {
        var that = this;
        console.log(that.adminList.nick_name);
        if (that.adminList.mobile == "") {
          that.$toast("电话不能为空");
        } else if (that.adminList.password == "") {
          that.$toast("密码不能为空");
        } else {
          var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
          if (!reg.test(that.adminList.mobile)) {
            that.$toast({
              message: "请输入有效的电话号码"
            });
          } else {
            $.ajax({
              url: "http://zcapi.hrgsxt.cn/api/User_data/admin_add",
              type: "post",
              dataType: "json",
              data: {
                token: that.token,
                name: that.adminList.name,
                password: that.adminList.password,
                nick_name: that.adminList.nick_name,
                mobile: that.adminList.mobile
              },
              success: function (res) {
                console.log(res);
                if (res.code === 200) {
                  that.$toast({
                    message: "添加成功"
                  });
                  that.$router.push({
                    path: "./adminlist",
                    query: {}
                  });
                }
              }
            });
          }
        }
      }
    }
  };
</script>

<style scoped>
  /* 头部 */

  .addadmin {
    width: 100%;
  }

  .my_header {
    width: 100%;
    height: 0.88rem;
    background: rgba(0, 133, 240, 1);
    /* text-align: center; */
    color: #fff;
    line-height: 0.88rem;
    position: fixed;
    z-index: 999;
    top: 0px;
    padding: 0 .2rem;
  }

  .my_header i {
    font-size: 0.4rem;
    float: left;
    line-height: 0.88rem;
  }

  .top1 {
    width: 40%;
    margin-left: 25%;
    float: left;
    text-align: center;
  }

  .head .headpic {
    width: 1rem;
    height: 1rem;
    margin: 0px 10px 0px 15px;
    border-radius: 50%;
  }

  .imgicon {
    width: 0.38rem;
    height: 0.4rem;
    position: absolute;
    top: 50%;
    right: 0.24rem;
    margin-top: -0.2rem;
  }

  .txlist {
    margin-top: 0.88rem;
  }

  .txlist .row {
    width: 100%;
    height: 0.88rem;
    background-color: #ffffff;
    line-height: 0.88rem;
    padding: 0px 0.35rem 0px 0.5rem;
    border-bottom: 1px solid #efefef;
    margin-bottom: 0.18rem;
  }

  .txlist .row:last-child {
    border-bottom: none;
  }

  .txlist .row .left {
    width: 24%;
    float: left;
    font-size: 0.3rem;
  }

  .txlist .row .left span {
    color: red;
    margin-right: 5px;
    margin-left: -9px;
  }

  .txlist .row .right {
    color: #666666;
    width: 73%;
    float: right;
    font-size: 0.26rem;
    line-height: 0.88rem;
    text-align: right;
    height: 0.88rem;
  }

  .txlist .row .right img {
    width: 0.14rem;
    height: 0.24rem;
    vertical-align: middle;
    margin-left: 7px;
    margin-bottom: 3px;
  }

  .txlist .row .right input {
    border: none;
    outline: none;
    text-align: right;
    padding-right: 0px !important;
  }

  .submit1 {
    background-color: #0085f0;
    font-size: 0.34rem;
    color: #ffffff;
    width: 90%;
    margin-left: 5%;
    height: 0.88rem;
    line-height: 0.88rem;
    border-radius: 12px;
    margin-bottom: 0.3rem;
    margin-top: 0.26rem;
  }
</style>
